﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.UI.HtmlControls;

namespace MyVocationSpace
{
    public partial class MyVocation : System.Web.UI.Page
    {
        public int CurrentPageMyCon = 0;
        public int totalPageMyCon;
        public int pageNoMyCon = 1;

        public int CurrentPageMyPend = 0;
        public int totalPageMyPend;
        public int pageNoMyPend = 1;

        public int CurrentPageMyMentor = 0;
        public int totalPageMyMentor;
        public int pageNoMyMentor = 1;

        public int CurrentPageMyMentorTopic = 0;
        public int totalPageMyMentorTopic;
        public int pageNoMyMentorTopic = 1;

        public int CurrentPageMyTopic = 0;
        public int totalPageMyTopic;
        public int pageNoMyTopic = 1;

        public int CurrentPageMyPendMentis = 0;
        public int totalPageMyPendMentis;
        public int pageNoMyPendMentis = 1;

        public int CurrentPageMyMentis = 0;
        public int totalPageMyMentis;
        public int pageNoMyMentis = 1;

        public int CurrentPageMentisTopic = 0;
        public int totalPageMentisTopic;
        public int pageNoMentisTopic = 1;

        protected void Page_Load(object sender, EventArgs e)
        {
            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
            if (Session["UserID"] != null)
            {
                if (!IsPostBack)
                {
                    PopulateMyConnection(Convert.ToInt32(Session["UserID"]));
                    PopulatePendingConnection(Convert.ToInt32(Session["UserID"]));
                    PopulateMentorTopic(Convert.ToInt32(Session["UserID"]));
                    PopulateMyMentor(Convert.ToInt32(Session["UserID"]));
                    PopulateMyTopic(Convert.ToInt32(Session["UserID"]));
                    PopulateMyPendingMentis(Convert.ToInt32(Session["UserID"]));
                    PopulateMyMentis(Convert.ToInt32(Session["UserID"]));
                    PopulateMentisTopic(Convert.ToInt32(Session["UserID"]));
                }
            }
            else
            {
                Response.Redirect("Home.aspx");
            }

        }

        public void PopulateMyConnection(int IDUser)
        {
            DataSet ds = BAL.Users.GetConnetionDetailByUSer(IDUser);

            PagedDataSource pgds = new PagedDataSource();
            pgds.DataSource = ds.Tables[0].DefaultView;

            int noOfItem = pgds.Count;
            pgds.AllowPaging = true;
            pgds.PageSize = 5;

            totalPageMyCon = pgds.PageCount;
            ViewState["TotalPageMyCon"] = totalPageMyCon;

            pgds.CurrentPageIndex = CurrentPageMyCon;
            ViewState["CurrentPageMyCon"] = CurrentPageMyCon;

            lbtnMyConnectionNext.Visible = !pgds.IsLastPage;
            lbtnMyConnectionPre.Visible = !pgds.IsLastPage;

            int currPageShow = Convert.ToInt32(ViewState["CurrentPageMyCon"]) + 1;
            Label1.Text = "Page " + currPageShow.ToString() + " of " + ViewState["TotalPageMyCon"].ToString();
            Label2.Text = noOfItem + " items found.Showing upto 10 items per page.";

            if (pgds.DataSource != null)
            {
                dlMyConnection.DataSource = pgds.DataSource;
                dlMyConnection.DataBind();
            }
        }

        protected void lbtnMyConnectionPre_Click(object sender, EventArgs e)
        {
            CurrentPageMyCon = Convert.ToInt32(ViewState["CurrentPageMyCon"]);
            CurrentPageMyCon -= 1;
            pageNoMyCon = Convert.ToInt32(ViewState["CurrentPageMyCon"]);
            pageNoMyCon -= 1;
            PopulateMyConnection(Convert.ToInt32(Session["UserID"]));

        }

        protected void lbtnMyConnectionNext_Click(object sender, EventArgs e)
        {
            CurrentPageMyCon = Convert.ToInt32(ViewState["CurrentPageMyCon"]);
            CurrentPageMyCon += 1;
            pageNoMyCon = Convert.ToInt32(ViewState["CurrentPageMyCon"]);
            pageNoMyCon += 1;
            PopulateMyConnection(Convert.ToInt32(Session["UserID"]));
        }

        protected void dlMyConnection_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Label labMyConnection = (Label)e.Item.FindControl("lblConMyConnection");
                HtmlImage htmlImg = (HtmlImage)e.Item.FindControl("imgPerson");

                int IdUser = Convert.ToInt32(dlMyConnection.DataKeys[e.Item.ItemIndex]);
                string img = htmlImg.Src;

                if (htmlImg.Src == "")
                {
                    htmlImg.Src = "UsersPhoto/icon_no_photo_60x60.png";
                }
                else
                {
                    htmlImg.Src = "UsersPhoto/" + img;
                }
                              

                int count = BAL.Users.GetConnectionByUser(IdUser);
                labMyConnection.Text = count.ToString() + " " + "<font style=\"color:#1C6F93; font-size:12px; font-weight:normal;\">connections</font>";

                LinkButton lnkConnectSend = (LinkButton)e.Item.FindControl("lnkConnectSend");
                HtmlGenericControl spanMYMentor = (HtmlGenericControl)e.Item.FindControl("spanMYMentor");

                HtmlInputHidden hdn = (HtmlInputHidden)e.Item.FindControl("hiddenIDMentorStatus");
                HtmlInputHidden hiddenIDMentorFlag = (HtmlInputHidden)e.Item.FindControl("hiddenIDMentorFlag");
                HtmlGenericControl idsuccesstick = (HtmlGenericControl)e.Item.FindControl("idsuccesstick");
                HtmlGenericControl spanSuccessMsg = (HtmlGenericControl)e.Item.FindControl("spanSuccessMsg");
                HtmlGenericControl spnsentMsg = (HtmlGenericControl)e.Item.FindControl("spnsentMsg");

                if (hdn.Value == "1")
                {
                    lnkConnectSend.Visible = false;
                    spanMYMentor.Visible = false;

                    idsuccesstick.Visible = true;
                    spanSuccessMsg.InnerHtml = "<font style=\"color:#BE2021; font-size:11px; font-weight:bold;\">Request has been sent</font>";
                }
                else if (hdn.Value == "2" && hiddenIDMentorFlag.Value=="2")
                {
                    lnkConnectSend.Visible = false;
                    spanMYMentor.Visible = false;

                    idsuccesstick.Visible = true;
                    spanSuccessMsg.InnerHtml = "<font style=\"color:#BE2021; font-size:12px; font-weight:bold;\">Mentees</font>";
                }

                else if (hdn.Value == "2" && hiddenIDMentorFlag.Value == "")
                {
                    lnkConnectSend.Visible = false;
                    spanMYMentor.Visible = false;

                    idsuccesstick.Visible = true;
                    spanSuccessMsg.InnerHtml = "<font style=\"color:#BE2021; font-size:12px; font-weight:bold;\">Mentor</font>";
                }

                else if (hdn.Value == "" || hdn.Value == "NULL")
                {
                    lnkConnectSend.Visible = true;
                    spanMYMentor.Visible = true;
                }
                else
                {
                    lnkConnectSend.Visible = true;
                    spanMYMentor.Visible = true;
                }


                lnkConnectSend.OnClientClick = "SendMentorReq(" + IdUser + ",'" + spnsentMsg.ClientID + "','" + spanMYMentor.ClientID + "','" + lnkConnectSend.ClientID + "');return false;";

            }
        }

        public void PopulatePendingConnection(int IDUser)
        {
            DataSet ds = BAL.Users.GetPendingConDetailByUSer(IDUser);

            PagedDataSource pgds = new PagedDataSource();
            pgds.DataSource = ds.Tables[0].DefaultView;

            int noOfItem = pgds.Count;
            pgds.AllowPaging = true;
            pgds.PageSize = 5;

            totalPageMyPend = pgds.PageCount;
            ViewState["TotalPageMyPend"] = totalPageMyPend;

            pgds.CurrentPageIndex = CurrentPageMyCon;
            ViewState["CurrentPageMyPend"] = CurrentPageMyPend;

            lbtnPendingConnPre.Visible = !pgds.IsLastPage;
            lbtnPendingConnNext.Visible = !pgds.IsLastPage;

            int currPageShow = Convert.ToInt32(ViewState["CurrentPageMyPend"]) + 1;
            Label3.Text = "Page " + currPageShow.ToString() + " of " + ViewState["TotalPageMyPend"].ToString();
            Label4.Text = noOfItem + " items found.Showing upto 10 items per page.";

            if (pgds.DataSource != null)
            {
                dlPendingConnection.DataSource = pgds.DataSource;
                dlPendingConnection.DataBind();
            }
        }

        protected void lnkPenConAccecpt_Click(object sender, EventArgs e)
        {
            LinkButton lnk = (LinkButton)sender;
            if (lnk != null)
            {
                int id = Convert.ToInt32(lnk.CommandArgument);
                BAL.Users.UpdateUserConnectionforAccept(id, Convert.ToInt32(Session["UserID"]));

                PopulatePendingConnection(Convert.ToInt32(Session["UserID"]));
                PopulateMyConnection(Convert.ToInt32(Session["UserID"]));
                //ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "SendConnectionAccept(" + id + ");", true);
            }            
        }

        protected void lnkPenConReject_Click(object sender, EventArgs e)
        {
            LinkButton lnk = (LinkButton)sender;
            if (lnk != null)
            {
                int id = Convert.ToInt32(lnk.CommandArgument);
                BAL.Users.UpdateUserConnectionforReject(id, Convert.ToInt32(Session["UserID"]));

                PopulatePendingConnection(Convert.ToInt32(Session["UserID"]));
                //ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "SendConnectionReject(" + id + ");", true);
            }
        }

        protected void lbtnPendingConnPre_Click(object sender, EventArgs e)
        {
            CurrentPageMyPend = Convert.ToInt32(ViewState["CurrentPageMyPend"]);
            CurrentPageMyPend -= 1;
            pageNoMyPend = Convert.ToInt32(ViewState["CurrentPageMyPend"]);
            pageNoMyPend -= 1;
            PopulateMyConnection(Convert.ToInt32(Session["UserID"]));
        }

        protected void lbtnPendingConnNext_Click(object sender, EventArgs e)
        {
            CurrentPageMyPend = Convert.ToInt32(ViewState["CurrentPageMyPend"]);
            CurrentPageMyPend += 1;
            pageNoMyPend = Convert.ToInt32(ViewState["CurrentPageMyPend"]);
            pageNoMyPend += 1;
            PopulateMyConnection(Convert.ToInt32(Session["UserID"]));
        }

        protected void dlPendingConnection_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Label labConPenConnection = (Label)e.Item.FindControl("lblConPenConnection");
                HtmlImage htmlImg = (HtmlImage)e.Item.FindControl("imgPersonPend");

                int IdUser = Convert.ToInt32(dlPendingConnection.DataKeys[e.Item.ItemIndex]);
                string img = htmlImg.Src;

                if (htmlImg.Src == "")
                {
                    htmlImg.Src = "UsersPhoto/icon_no_photo_60x60.png";
                }
                else
                {
                    htmlImg.Src = "UsersPhoto/" + img;
                }

                int count = BAL.Users.GetConnectionByUser(IdUser);
                labConPenConnection.Text = count.ToString() + " " + "<font style=\"color:#1C6F93; font-size:12px; font-weight:normal;\">connections</font>";

            }
        }

        protected void lnkConnectSend_Click(object sender, EventArgs e)
        {
            //LinkButton lnk = (LinkButton)sender;

            //if (lnk != null)
            //{
            //    int id = Convert.ToInt32(lnk.CommandArgument);
            //    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "SendMentorReq(" + id + ");", true);

            //}
        }

        public void PopulateMentorTopic(int IDUser)
        {
            DataSet ds = BAL.Topics.GetTopicOfMentorByUser(IDUser);

            PagedDataSource pgds = new PagedDataSource();
            pgds.DataSource = ds.Tables[0].DefaultView;

            int noOfItem = pgds.Count;
            pgds.AllowPaging = true;
            pgds.PageSize = 10;

            totalPageMyMentorTopic = pgds.PageCount;
            ViewState["totalPageMyMentorTopic"] = totalPageMyMentorTopic;

            pgds.CurrentPageIndex = CurrentPageMyMentorTopic;
            ViewState["CurrentPageMyMentorTopic"] = CurrentPageMyMentorTopic;

            lnkMyMentorTopicPre.Visible = !pgds.IsLastPage;
            lnkMyMentorTopicNext.Visible = !pgds.IsLastPage;

            int currPageShow = Convert.ToInt32(ViewState["CurrentPageMyMentorTopic"]) + 1;
            Label9.Text = "Page " + currPageShow.ToString() + " of " + ViewState["totalPageMyMentorTopic"].ToString();
            Label10.Text = noOfItem + " items found.Showing upto 10 items per page.";

            if (pgds.DataSource != null)
            {
                dlMyMentorTopic.DataSource = pgds.DataSource;
                dlMyMentorTopic.DataBind();
            }
        }

        protected void dlMyMentorTopic_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            
        }


        protected void lnkMyMentorTopicPre_Click(object sender, EventArgs e)
        {
            CurrentPageMyMentorTopic = Convert.ToInt32(ViewState["CurrentPageMyPendMentor"]);
            CurrentPageMyMentorTopic -= 1;
            pageNoMyMentorTopic = Convert.ToInt32(ViewState["CurrentPageMyPendMentor"]);
            pageNoMyMentorTopic -= 1;
            PopulateMentorTopic(Convert.ToInt32(Session["UserID"]));
        }

        protected void lnkMyMentorTopicNext_Click(object sender, EventArgs e)
        {
            CurrentPageMyMentorTopic = Convert.ToInt32(ViewState["CurrentPageMyPendMentor"]);
            CurrentPageMyMentorTopic += 1;
            pageNoMyMentorTopic = Convert.ToInt32(ViewState["CurrentPageMyPendMentor"]);
            pageNoMyMentorTopic += 1;
            PopulateMentorTopic(Convert.ToInt32(Session["UserID"]));
        }

        
        public void PopulateMyMentor(int IDUser)
        {
            DataSet ds = BAL.Users.GetMyMentorDetailByUser(IDUser);

            PagedDataSource pgds = new PagedDataSource();
            pgds.DataSource = ds.Tables[0].DefaultView;

            int noOfItem = pgds.Count;
            pgds.AllowPaging = true;
            pgds.PageSize = 10;

            totalPageMyMentor = pgds.PageCount;
            ViewState["totalPageMyMentor"] = totalPageMyMentor;

            pgds.CurrentPageIndex = CurrentPageMyMentor;
            ViewState["CurrentPageMyMentor"] = CurrentPageMyMentor;

            lnkMyMentorPre.Visible = !pgds.IsLastPage;
            lnkMyMentorNext.Visible = !pgds.IsLastPage;

            int currPageShow = Convert.ToInt32(ViewState["CurrentPageMyMentor"]) + 1;
            Label5.Text = "Page " + currPageShow.ToString() + " of " + ViewState["totalPageMyMentor"].ToString();
            Label6.Text = noOfItem + " items found.Showing upto 10 items per page.";

            if (pgds.DataSource != null)
            {
                dlMyMentor.DataSource = pgds.DataSource;
                dlMyMentor.DataBind();
            }
        }

        protected void dlMyMentor_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Label lblMyMentor = (Label)e.Item.FindControl("lblConMyMentor");
                HtmlImage htmlImg = (HtmlImage)e.Item.FindControl("imgPersonMyMentor");

                int IdUser = Convert.ToInt32(dlMyMentor.DataKeys[e.Item.ItemIndex]);
                string img = htmlImg.Src;

                if (htmlImg.Src == "")
                {
                    htmlImg.Src = "UsersPhoto/icon_no_photo_60x60.png";
                }
                else
                {
                    htmlImg.Src = "UsersPhoto/" + img;
                }

                int count = BAL.Users.GetConnectionByUser(IdUser);
                lblMyMentor.Text = count.ToString() + " " + "<font style=\"color:#1C6F93; font-size:12px; font-weight:normal;\">connections</font>";
            }
        }

        protected void lnkMyMentorPre_Click(object sender, EventArgs e)
        {
            CurrentPageMyMentor = Convert.ToInt32(ViewState["CurrentPageMyMentor"]);
            CurrentPageMyMentor -= 1;
            pageNoMyMentor = Convert.ToInt32(ViewState["CurrentPageMyMentor"]);
            pageNoMyMentor -= 1;
            PopulateMyMentor(Convert.ToInt32(Session["UserID"]));
        }

        protected void lnkMyMentorNext_Click(object sender, EventArgs e)
        {
            CurrentPageMyMentor = Convert.ToInt32(ViewState["CurrentPageMyMentor"]);
            CurrentPageMyMentor += 1;
            pageNoMyMentor = Convert.ToInt32(ViewState["CurrentPageMyMentor"]);
            pageNoMyMentor += 1;
            PopulateMyMentor(Convert.ToInt32(Session["UserID"]));
        }

        public void PopulateMyTopic(int IDUser)
        {
            DataSet ds = BAL.Topics.GetTopicByUser(IDUser);

            PagedDataSource pgds = new PagedDataSource();
            pgds.DataSource = ds.Tables[0].DefaultView;

            int noOfItem = pgds.Count;
            pgds.AllowPaging = true;
            pgds.PageSize = 5;

            totalPageMyTopic = pgds.PageCount;
            ViewState["TotalPageMyTopic"] = totalPageMyTopic;

            pgds.CurrentPageIndex = CurrentPageMyTopic;
            ViewState["CurrentPageMyTopic"] = CurrentPageMyTopic;

            lnkPreTopic.Visible = !pgds.IsLastPage;
            lnkNextTopic.Visible = !pgds.IsLastPage;

            int currPageShow = Convert.ToInt32(ViewState["CurrentPageMyTopic"]) + 1;
            Label11.Text = "Page " + currPageShow.ToString() + " of " + ViewState["TotalPageMyTopic"].ToString();
            Label12.Text = noOfItem + " items found.Showing upto 10 items per page.";

            if (pgds.DataSource != null)
            {
                dlMyTopic.DataSource = pgds.DataSource;
                dlMyTopic.DataBind();
            }
        }

        protected void lnkPreTopic_Click(object sender, EventArgs e)
        {
            CurrentPageMyTopic = Convert.ToInt32(ViewState["CurrentPageMyTopic"]);
            CurrentPageMyTopic -= 1;
            pageNoMyTopic = Convert.ToInt32(ViewState["CurrentPageMyTopic"]);
            pageNoMyTopic -= 1;
            PopulateMyTopic(Convert.ToInt32(Session["UserID"]));
        }

        protected void lnkNextTopic_Click(object sender, EventArgs e)
        {
            CurrentPageMyTopic = Convert.ToInt32(ViewState["CurrentPageMyTopic"]);
            CurrentPageMyTopic += 1;
            pageNoMyTopic = Convert.ToInt32(ViewState["CurrentPageMyTopic"]);
            pageNoMyTopic += 1;
            PopulateMyTopic(Convert.ToInt32(Session["UserID"]));
        }

        public void PopulateMyPendingMentis(int IDUser)
        {
            DataSet ds = BAL.Users.GetPendingMentisDetailByUser(IDUser);

            PagedDataSource pgds = new PagedDataSource();
            pgds.DataSource = ds.Tables[0].DefaultView;

            int noOfItem = pgds.Count;
            pgds.AllowPaging = true;
            pgds.PageSize = 10;

            totalPageMyPendMentis = pgds.PageCount;
            ViewState["TotalPageMyPendMentis"] = totalPageMyPendMentis;

            pgds.CurrentPageIndex = CurrentPageMyPendMentis;
            ViewState["CurrentPageMyPendMentis"] = CurrentPageMyPendMentis;

            lnkPendMentisNext.Visible = !pgds.IsLastPage;
            lnkPendMentisPre.Visible = !pgds.IsLastPage;

            int currPageShow = Convert.ToInt32(ViewState["CurrentPageMyPendMentis"]) + 1;
            Label15.Text = "Page " + currPageShow.ToString() + " of " + ViewState["TotalPageMyPendMentis"].ToString();
            Label16.Text = noOfItem + " items found.Showing upto 10 items per page.";

            if (pgds.DataSource != null)
            {
                dlMyPendingMentis.DataSource = pgds.DataSource;
                dlMyPendingMentis.DataBind();
            }
        }

        protected void lnkPendMentisAccecpt_Click(object sender, EventArgs e)
        {
            LinkButton lnk = (LinkButton)sender;
            if (lnk != null)
            {
                int id = Convert.ToInt32(lnk.CommandArgument);
                BAL.Users.UpdateUserMentorforAccept(id, Convert.ToInt32(Session["UserID"]));
            }

            PopulateMyMentis(Convert.ToInt32(Session["UserID"]));
            PopulateMyPendingMentis(Convert.ToInt32(Session["UserID"]));
            PopulateMyConnection(Convert.ToInt32(Session["UserID"]));
            //AsyncPostBackTrigger asynpost = new AsyncPostBackTrigger();
            //asynpost.ControlID = "id";
            //asynpost.EventName = "Click";
            //UpdatePanelMentees.Triggers.Add(asynpost);
            //UpdatePanelMentees.Update();
        }

        protected void lnkPendMentisReject_Click(object sender, EventArgs e)
        {
            LinkButton lnk = (LinkButton)sender;
            if (lnk != null)
            {
                int id = Convert.ToInt32(lnk.CommandArgument);
                //ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "MentorRequestReject(" + id + ");", true);
                BAL.Users.UpdateUserMentorforReject(id, Convert.ToInt32(Session["UserID"]));
            }

            PopulateMyPendingMentis(Convert.ToInt32(Session["UserID"]));
        }

        protected void lnkPendMentisPre_Click(object sender, EventArgs e)
        {
            CurrentPageMyPendMentis = Convert.ToInt32(ViewState["CurrentPageMyPendMentis"]);
            CurrentPageMyPendMentis -= 1;
            pageNoMyPendMentis = Convert.ToInt32(ViewState["CurrentPageMyPendMentis"]);
            pageNoMyPendMentis -= 1;
            PopulateMyPendingMentis(Convert.ToInt32(Session["UserID"]));
        }

        protected void lnkPendMentisNext_Click(object sender, EventArgs e)
        {
            CurrentPageMyPendMentis = Convert.ToInt32(ViewState["CurrentPageMyPendMentis"]);
            CurrentPageMyPendMentis += 1;
            pageNoMyPendMentis = Convert.ToInt32(ViewState["CurrentPageMyPendMentis"]);
            pageNoMyPendMentis += 1;
            PopulateMyPendingMentis(Convert.ToInt32(Session["UserID"]));
        }

        protected void dlMyPendingMentis_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Label lblPendMentis = (Label)e.Item.FindControl("lblConMyPendingMentis");
                HtmlImage htmlImg = (HtmlImage)e.Item.FindControl("imgPersonPendMentis");

                int IdUser = Convert.ToInt32(dlMyPendingMentis.DataKeys[e.Item.ItemIndex]);
                string img = htmlImg.Src;

                if (htmlImg.Src == "")
                {
                    htmlImg.Src = "UsersPhoto/icon_no_photo_60x60.png";
                }
                else
                {
                    htmlImg.Src = "UsersPhoto/" + img;
                }

                int count = BAL.Users.GetConnectionByUser(IdUser);
                lblPendMentis.Text = count.ToString() + " " + "<font style=\"color:#1C6F93; font-size:12px; font-weight:normal;\">connections</font>";
            }
        }


        public void PopulateMyMentis(int IDUser)
        {
            DataSet ds = BAL.Users.GetMyMentisDetailByUser(IDUser);

            PagedDataSource pgds = new PagedDataSource();
            pgds.DataSource = ds.Tables[0].DefaultView;

            int noOfItem = pgds.Count;
            pgds.AllowPaging = true;
            pgds.PageSize = 10;

            totalPageMyMentis = pgds.PageCount;
            ViewState["TotalPageMyMentis"] = totalPageMyMentis;

            pgds.CurrentPageIndex = CurrentPageMyMentis;
            ViewState["CurrentPageMyMentis"] = CurrentPageMyMentis;

            lnkMyMentisPre.Visible = !pgds.IsLastPage;
            lnkMyMentisNext.Visible = !pgds.IsLastPage;

            int currPageShow = Convert.ToInt32(ViewState["CurrentPageMyMentis"]) + 1;
            Label13.Text = "Page " + currPageShow.ToString() + " of " + ViewState["TotalPageMyMentis"].ToString();
            Label14.Text = noOfItem + " items found.Showing upto 10 items per page.";

            if (pgds.DataSource != null)
            {
                dlMyMentis.DataSource = pgds.DataSource;
                dlMyMentis.DataBind();
            }
        }

        protected void lnkMyMentisPre_Click(object sender, EventArgs e)
        {
            CurrentPageMyMentis = Convert.ToInt32(ViewState["CurrentPageMyMentis"]);
            CurrentPageMyMentis -= 1;
            pageNoMyMentis = Convert.ToInt32(ViewState["CurrentPageMyMentis"]);
            pageNoMyMentis -= 1;
            PopulateMyMentis(Convert.ToInt32(Session["UserID"]));
        }

        protected void lnkMyMentisNext_Click(object sender, EventArgs e)
        {
            CurrentPageMyMentis = Convert.ToInt32(ViewState["CurrentPageMyMentis"]);
            CurrentPageMyMentis += 1;
            pageNoMyMentis = Convert.ToInt32(ViewState["CurrentPageMyMentis"]);
            pageNoMyMentis += 1;
            PopulateMyMentis(Convert.ToInt32(Session["UserID"]));
        }

        protected void dlMyMentis_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Label lblMentis = (Label)e.Item.FindControl("lblMyMentis");
                HtmlImage htmlImg = (HtmlImage)e.Item.FindControl("imgPersonMyMentis");

                int IdUser = Convert.ToInt32(dlMyMentis.DataKeys[e.Item.ItemIndex]);
                string img = htmlImg.Src;

                if (htmlImg.Src == "")
                {
                    htmlImg.Src = "UsersPhoto/icon_no_photo_60x60.png";
                }
                else
                {
                    htmlImg.Src = "UsersPhoto/" + img;
                }

                int count = BAL.Users.GetConnectionByUser(IdUser);
                lblMentis.Text = count.ToString() + " " + "<font style=\"color:#1C6F93; font-size:12px; font-weight:normal;\">connections</font>";

            }
        }

        public void PopulateMentisTopic(int IDUser)
        {
            DataSet ds = BAL.Topics.GetTopicOfMentisByUser(IDUser);

            PagedDataSource pgds = new PagedDataSource();
            pgds.DataSource = ds.Tables[0].DefaultView;

            int noOfItem = pgds.Count;
            pgds.AllowPaging = true;
            pgds.PageSize = 10;

            totalPageMentisTopic = pgds.PageCount;
            ViewState["TotalPageMentisTopic"] = totalPageMentisTopic;

            pgds.CurrentPageIndex = CurrentPageMentisTopic;
            ViewState["CurrentPageMentisTopic"] = CurrentPageMentisTopic;

            lnkMentisTopicPre.Visible = !pgds.IsLastPage;
            lnkMentisTopicNext.Visible = !pgds.IsLastPage;

            int currPageShow = Convert.ToInt32(ViewState["CurrentPageMentisTopic"]) + 1;
            Label7.Text = "Page " + currPageShow.ToString() + " of " + ViewState["TotalPageMentisTopic"].ToString();
            Label8.Text = noOfItem + " items found.Showing upto 10 items per page.";

            if (pgds.DataSource != null)
            {
                dlMentisTopic.DataSource = pgds.DataSource;
                dlMentisTopic.DataBind();
            }
        }

        protected void lnkMentisTopicPre_Click(object sender, EventArgs e)
        {
            CurrentPageMentisTopic = Convert.ToInt32(ViewState["CurrentPageMentisTopic"]);
            CurrentPageMentisTopic -= 1;
            pageNoMentisTopic = Convert.ToInt32(ViewState["CurrentPageMentisTopic"]);
            pageNoMentisTopic -= 1;
            PopulateMentisTopic(Convert.ToInt32(Session["UserID"]));
        }

        protected void lnkMentisTopicNext_Click(object sender, EventArgs e)
        {
            CurrentPageMentisTopic = Convert.ToInt32(ViewState["CurrentPageMentisTopic"]);
            CurrentPageMentisTopic += 1;
            pageNoMentisTopic = Convert.ToInt32(ViewState["CurrentPageMentisTopic"]);
            pageNoMentisTopic += 1;
            PopulateMentisTopic(Convert.ToInt32(Session["UserID"]));
        }

        protected void dlPendingConnection_ItemCommand(object source, DataListCommandEventArgs e)
        {
           
        }

        

    }
}